compress the string hackerrank solution in pyhton